// pages/classify/classify.js
import {
  goodsList,
  category,
  addCart
} from "../../utils/http";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeKey: 0,
    categoryList: [],
    goodsLists: [],
    id: 327657
  },
  addcarts(e){
    console.log(e);
    addCart({goodsId:e.currentTarget.dataset.info.id,number:1,token:wx.getStorageSync('token')}).then(res=>{
        console.log(res);
    })
},
  getclassify(e) {
    console.log(e);

    let {
      goodsLists,
      id
    } = this.data;
    id = e.currentTarget.dataset.id
    this.setData({
      id
    })
    console.log(id);
    goodsList({categoryId: id}).then(ress => {
      console.log('123', ress);
      if(ress.data){
        
        goodsLists = ress.data.result
      }else{
        goodsLists=[]
        console.log('暂无数据');
      }
      
      console.log(goodsLists);
      this.setData({
        goodsLists
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {
      categoryList
    } = this.data;

    category().then(ress => {
      console.log(ress);
      categoryList = ress.data
      console.log(categoryList);
      this.setData({
        categoryList
      })
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})